package com.zhouyang.imtest.service.impl;

import com.zhouyang.imtest.dao.MessageDao;
import com.zhouyang.imtest.entity.Message;
import com.zhouyang.imtest.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:ZhouYang
 * @Description:
 * @Date: Created in 2020/7/16 15:48
 * @Modified By：
 */
@Service
public class MessageServiceImpl implements MessageService {


    @Autowired
    private MessageDao messageDao;

    @Override
    public List<Message> queryMessageList(Long fromId, Long toId, Integer page, Integer rows) {
        List<Message> listByFromAndTo = messageDao.findListByFromAndTo(fromId, toId, page, rows);
        listByFromAndTo.stream().forEach(message -> {
                if(message.getStatus().intValue() == 1){
                        //标记状态为已读
                    messageDao.updateMessageState(message.getId(),2);
                }
        });
        return listByFromAndTo;
    }
}
